package com.zzyl.member.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzyl.common.core.domain.R;
import com.zzyl.member.dto.servceListDTO;
import com.zzyl.member.vo.TimeReservationCountVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.member.domain.Reservation;
import com.zzyl.member.service.IReservationService;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class ReservationController extends BaseController {
    @Autowired
    private IReservationService reservationService;


    @GetMapping("/cancelled-count")
    @ApiOperation(value = "获取已取消预约数量")
    public AjaxResult getCancelledCount() {
        return AjaxResult.success(reservationService.getCancelledCount());
    }

    /**
     * 获取时间段可预约次数
     *
     * @return
     */
    @GetMapping("/countByTime")
    @ApiOperation(value = "获取时间段预约次数")
    public AjaxResult getReservationCountByTime(Long time) {
        List<TimeReservationCountVO> list = reservationService.getReservationCountByTime(time);
        return AjaxResult.success(list);
    }

    /**
     * 新增预约
     */
    @PostMapping
    @ApiOperation(value = "新增预约")
    public AjaxResult add(@RequestBody Reservation reservation) {
        return toAjax(reservationService.insertReservation(reservation));
    }

    /**
     * 分页查询预约
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询预约")
    public R<TableDataInfo<Reservation>> list(servceListDTO servceListDTO) {
        IPage<Reservation> list = reservationService.selectReservationList(servceListDTO);
        return R.ok(getDataTable(list.getRecords()));
    }

    /**
     * 取消预约
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation(value = "取消预约")
    public AjaxResult cancel(@PathVariable("id") Integer id) {
        reservationService.updateReservation(id);
        return success();
    }
}
